mui.init({
	swipeBack: false, //右滑关闭功能
});
if (window.plus) {
	plusReady();
} else {
	document.addEventListener('plusready', plusReady, false);
}
var biz,bizname;

function plusReady() {
	var current = plus.webview.currentWebview();
	biz = current.biz;
	bizname = current.bizname;
	$("#zclist_title").text(bizname + "待办");
	loadListData();

	//返回首页
	document.getElementById('home').addEventListener('tap', function() {
		var h = plus.webview.getWebviewById('mainpage');
		plus.webview.show(h);
		mui.fire(h, 'tabClick', {
			tabId: 'defaultTab'
		});
	});
	document.addEventListener('loadListData', loadListData);
}
//下边是实现全选/全不选
function checked() {
	var a = document.getElementsByTagName("input");
	if (a.length==0) {
		mui.toast("对不起，没有可选项");
		return;
	}
	if (a[0].checked) {
		for (var i = 0; i < a.length; i++) {
			if (a[i].type=="checkbox") {
				a[i].checked=false;
			}
			document.getElementById("allselect").innerHTML="<i class=\"fa fa-check-circle pan_color_primary\"></i>&nbsp;全选";
		}
		
	} else{
		for (var i = 0; i < a.length; i++) {
			if (a[i].type="checkbox") {
				a[i].checked=true;
			}
			document.getElementById("allselect").innerHTML="<i class=\"fa fa-circle-o pan_color_primary\"></i>&nbsp;全不选";
		}
	}

}
//批量审核
function approval() {
	var a = document.getElementsByTagName("input");
	var num=0;
	var spbNoLists="";//记录要审批的编号列表
	
	for (var i = 0; i < a.length; i++) {
		if (a[i].type=="checkbox" && a[i].checked) {
			num++;
			spbNoLists += "," + a[i].id;//最前面多一个,后面处理掉
			//console.log(a[i].id);
		}
	}
	
	if (num <= 0) {
		mui.toast("请选择");
		return;
	} else{
		spbNoLists=spbNoLists.substr(1);//去掉前面的,
		var token = plus.storage.getItem("token");
		if (token == null || token=="") {
			return;
		} else{
			mui.ajax(baseServerAdrr+"/zc/approveSPB", {
				data:{
					token:token,
					bizNo:spbNoLists,
					bizType:biz
				},
				dataType: 'json', //服务器返回json格式数据
				type: 'post', //HTTP请求类型
				timeout: 30000, //超时时间设置为10秒
				success:function (data) {
					//panUtil.ajaxLoding.stop();
					if (data.code == "success") {
						mui.toast(data.message);
						loadListData();
					} else{
						mui.toast(data.message);
						setTimeout(function(){
		   	    		panUtil.ReLogin();
		   	    		},1000);
					}
					
				},
				error:function	(xhr,type,errorThrown){
					//异常处理；
					//panUtil.ajaxLoding.stop();
					mui.toast('服务器异常登录失败! zcsplb.js');				
				}
			});
		}
	}
	
}
//加载自身页面信息
function loadListData() {

	var token = plus.storage.getItem("token");
	if (token == null || token == "") {
		return;
	} else {
		panUtil.ajaxLoding.start();
		mui.ajax(baseServerAdrr+'/zc/getSPLB', {
			data: {
				token: token,
				ywlx: biz,
				splx: 'noApprove'
			},
			dataType: 'json', //服务器返回json格式数据
			type: 'post', //HTTP请求类型
			timeout: 30000, //超时时间设置为10秒；
			success: function(data) {
				panUtil.ajaxLoding.stop();
				if (data.code == 'success') {
					initlist(data.message);
				} else {
					mui.toast(data.message);
					setTimeout(function() {
						panUtil.ReLogin();
					}, 1000);
				}
			},
			error: function(xhr, type, errorThrown) {
				//异常处理；
				panUtil.ajaxLoding.stop();
				mui.toast('服务器异常登录失败!');
			}
		});
	}
}


function detailclick(spbh,biz) {
	var listview = mui.openWindow({
		url: "zcspdetail.html",
		id: "zcspdetail",
		extras: {
			bizType : biz,
			bizNo  : spbh,
			bizName  : bizname,
			splx:"dsp"
		},
		createNew: false,
		waiting: {
			autoShow: false
		}
	});
}
//重写返回事件
var old_back = mui.back;
mui.back = function() {
	var h = plus.webview.getWebviewById("zctoDoTab.html");
	mui.fire(h, "loadTodoData");
	//继续当前页面原有返回逻辑
	old_back();
}

function initlist(datas) {
	$("#zclistul").html();
	var datastr = "";
	for (var i = 0; i < datas.length; i++) {
		var data = datas[i];
		datastr += '<li class="mui-table-view-cell mui-checkbox mui-left">';
		datastr += '<input name="checkbox" type="checkbox" id="' + data.SPBBH + '" style="line-height: 60px;">';
		datastr += '<div class="mui-table">';
		datastr += '<div class="mui-table-cell mui-col-xs-11"><span style="font-size:15px">申请单位:' + data.SPBDEPT + '&nbsp;&nbsp;<br/><span style="font-size:14px">资产数量:' + data.AMOUNT + '&nbsp;&nbsp; 资产原值:' + data.ZCYZ + '</span></span></div>';
		datastr += '<a class="mui-navigate-right zcliststyle"  href="javascript:void(0)" onclick="detailclick(\'' + data.SPBBH + '\',\'' + biz + '\');">';
		datastr += '<div style="height:20px;margin:0px;"></div>';
		datastr += '</a></div></li>';
	}
	$("#zclistul").html(datastr);
}